package com.xidian.GMS.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.UserInfo;
import com.xidian.GMS.entity.UserInfoWithBLOBs;
import com.xidian.GMS.service.UserInfoService;

@Controller
public class UserInfoController {

	@Autowired
	 private UserInfoService  UserInfoService;
	
	
	@RequestMapping(value="/UserInfoEdit",method= RequestMethod.GET)
	public String update0(int userid ,Model  model){
		    model.addAttribute("userid", userid);
			return "UserInfoEdit";
			// TODO: handle exception
		
	}


	@RequestMapping(value="/UserInfoEdit",method= RequestMethod.POST)
	public String update(UserInfoWithBLOBs UserInfo){
		
		UserInfoService.update(UserInfo);
		
			return "UserInfoIndex";
	}
	
	

	@RequestMapping(value="/UserInfoInsert",method= RequestMethod.POST)
	public String Insert(UserInfoWithBLOBs UserInfo){
		
		try {	
			System.out.println(UserInfo);
		    UserInfoService.Insert( UserInfo);
		    
			return "UserInfoIndex";
		} catch (Exception e) {
			return "UserInfoInsert";
			// TODO: handle exception
		}
		
	}
	@RequestMapping(value="/UserInfoInsert",method= RequestMethod.GET)
	public String Insert(){

			return "UserInfoInsert";
			// TODO: handle exception
		
		
	}
	@RequestMapping(value="/UserInfo",method= RequestMethod.GET)
	public String Insert22(){

			return "UserInfo";
			// TODO: handle exception
		
		
	}
	@RequestMapping(value="/UserInfoDelete",method= RequestMethod.GET)
	public String delete(int uid){
		try {
			UserInfoService.delete(uid);
			return "forward:/fun8-userInfo.html";
		} catch (Exception e) {
			return "UserInfoInsert";
			// TODO: handle exception
		}
		
	}

	@RequestMapping(value="/UserInfoIndex",method= RequestMethod.POST)
	public String IndexPost(){

			return "UserInfoIndex";
			// TODO: handle exception
		}
		

	@RequestMapping(value="/UserInfoIndex",method= RequestMethod.GET)
	@ResponseBody
	public Page index(@RequestParam(name="cur", defaultValue="1") int cur, Model model){
		Page page = UserInfoService.getUserInfo(cur);
		System.out.println(page);
	 	model.addAttribute("page", page);
	 	
			return page;
			// TODO: handle exception
		
		
	}

}
